AddPurchaseOrderWindowCreator = Ext.extend(Ext.app.Module, {
	id : 'addPurchaseOrderWindowCreator',
	type : 'common/notepad',
	
	init : function() {
//		this.ordersName = '非在线采购订单' || '在线采购订单';
	},
	getTypeWindow : function() {
		return AddPurchaseOrderWindow;
	},
	
	win_index : 1,
	
	createWindow : function(initParams) {
		
		if(initParams.record && !(initParams.record.data.discount)) {
			Ext.Msg.alert('提示', '对不起，对方供应商刚刚更新了数据，请刷新报价信息窗口或重新打开报价信息窗口.');
			return;
		}
		
		var desktop = this.app.getDesktop();
		
		var showQuotationWin = desktop.getWindow('showQuotationWindow');
		if(showQuotationWin && initParams.companyId && showQuotationWin[initParams.companyId]) {
			var win = showQuotationWin[initParams.companyId];

			win.curr_record = initParams.record ? initParams.record : null;
			win.show();
			return;
		}
				
		var init_buyerCode = initParams.init_buyerCode ? initParams.init_buyerCode : '';
		var flag = false;
		var ref = this;
	
		desktop.windows.each(function(win) {

			if(win.creator && win.creator == ref) {
				if(initParams.companyId ) {
					if((initParams.companyId + '').trim() == win.purchase_seller_id_hidden.getValue() && win.buyerCode == '') {
						win.curr_record = initParams.record ? initParams.record : null;
						win.createLinkQuotaWindow(initParams);
						win.show();
						flag = true;
						return false;
					}
				} else if(init_buyerCode == '') {
					if(win.creator.ordersNameEn + win.buyerCode == ref.ordersNameEn + init_buyerCode && !win.partner_combox.getValue()) {
						win.createLinkQuotaWindow(initParams);
						win.show();
						flag = true;
						return false;
					}
				} else {
					if(win.creator.ordersNameEn + win.buyerCode == ref.ordersNameEn + init_buyerCode) {
						win.createLinkQuotaWindow(initParams);
						win.show();
						flag = true;
						return false;
					}
				}
			}
			
		});

		if (flag) {
			return;
		}
		
		
		var versionCode = ++(PurchaseCount.count);
		
		this.typeWindow = this.getTypeWindow();
		
		var main_win = desktop.createWindow({
			buyerCode : init_buyerCode,
			title : this.ordersName + init_buyerCode,
			width : 1020,
			height : 535,
			iconCls : 'acc-icon',
			animCollapse : true,
            constrainHeader : true,
            maximizable : true,
			taskbuttonTooltip : this.ordersName,
			layout : "fit",
			items : []
		}, this.typeWindow);
		
		main_win.creator = this;
		main_win.versionCode = versionCode;
		main_win.initPanel(initParams);
		
		main_win.curr_record = initParams.record ? initParams.record : null;
		
		main_win.creatorIndex = this.win_index;
		
		main_win.createLinkQuotaWindow(initParams);
		
		this[this.win_index++] = main_win;
		
		main_win.show();
		
	}
});